/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jefoutta
 */

import java.util.*;

public class ProcQueue {

    public static LinkedList<Integer> queue_list = new LinkedList();
    public Integer id;
    public String name;
    public Integer type;
    public Integer quantum;
    public Integer preemptive;
    public Integer queueOnQuantumEnd;
    public Integer queueOnIOEnd;
    private LinkedList<Integer> FCFS = new LinkedList();
    private PriorityQueue<Integer> PRIORITY = new PriorityQueue(100,new Comparator<Integer>(){
        public int compare(Integer x, Integer y){
                if (PCB.proc_id.get(x).priority < PCB.proc_id.get(y).priority)
                    return(1);
                if (x == y)
                    return(0);
                return(-1);
            }
            });
    private PriorityQueue<Integer> SJF = new PriorityQueue(100,new Comparator<Integer>(){
        public int compare(Integer x, Integer y){
                if (PCB.proc_id.get(x).job > PCB.proc_id.get(y).job)
                    return(1);
                if (x == y)
                    return(0);
                return(-1);
            }
            });
    public static Hashtable<Integer,ProcQueue> procQueues = new Hashtable();

    public ProcQueue(Integer tid, String tname, Integer ttype, Integer tquantum, Integer tpreemptive, Integer tqueueOnQuantumEnd, Integer tqueueOnIOEnd){
        id = tid;
        name = tname;
        type = ttype;
        quantum = tquantum;
        preemptive = tpreemptive;
        queueOnQuantumEnd = tqueueOnQuantumEnd;
        queueOnIOEnd = tqueueOnIOEnd;
        procQueues.put(id, this);
    }

    public ProcQueue(Integer tid){
        id = tid;
        preemptive = 0;
        procQueues.put(id, this);
    }

    public ProcQueue(String[] s){
        this.id = Integer.parseInt(s[0]);
        this.name = s[1];
        this.type = Integer.parseInt(s[2]);
        this.quantum = Integer.parseInt(s[3]);
        this.preemptive = Integer.parseInt(s[4]);
        this.queueOnQuantumEnd = Integer.parseInt(s[5]);
        this.queueOnIOEnd = Integer.parseInt(s[6]);
        queue_list.add(id);
    }

    public Integer poll(){
        Integer n = null;
        switch(this.type){
            case 1: n = FCFS.poll();
            break;
            case 2: n = SJF.poll();
            break;
            case 3: n = PRIORITY.poll();
            break;
        }
        return n;
    }

    public Integer peek(){
        Integer n = null;
        switch(this.type){
            case 1: n = FCFS.peek();
            break;
            case 2: n = SJF.peek();
            break;
            case 3: n = PRIORITY.peek();
            break;
        }
        return n;
    }

    public void add(Integer id){
        switch(this.type){
            case 1: FCFS.addLast(id);
            break;
            case 2: SJF.add(id);
            break;
            case 3: PRIORITY.add(id);
            break;
        }
    }

    public boolean isEmpty(){
        boolean b = true;
        switch(this.type){
            case 1: b = FCFS.isEmpty();
            break;
            case 2: b = SJF.isEmpty();
            break;
            case 3: b = PRIORITY.isEmpty();
            break;
        }
        return b;
    }

    public Integer getSize(){
        Integer n = null;
        switch(this.type){
            case 1: n = FCFS.size();
            break;
            case 2: n = SJF.size();
            break;
            case 3: n = PRIORITY.size();
            break;
        }
        return n;
    }
}